package main

import "fmt"

// 编译
// 在GOPATH下运行命令
// go build hell0world01/08funcbase/func02/model
// go build -o bin\my.exe hell0world01/08funcbase/func02/model
// ~函数本身也是一种类型
func main() {

	//test01()
	//test02()
	testExchangeAsParam()
}

func test01() {
	methodSum := sum
	fmt.Printf("type: %T , value: %v\n", methodSum, methodSum)
	res := sumAsParam(sum, 99, 88)
	fmt.Printf("type: %T , value: %v\n", res, res)
}

func test02() {
	method := expend
	n3, n4 := expendAsParam(method, 33, 44)
	fmt.Printf("n3 =%v  n4=%v \n", n3, n4)
}

func sum(n1 int, n2 int) int {
	return n1 + n2
}

// sumAsParam
//
//	@Description: 将sum方法作为参数:参数
//	@param sum sum  将sum方法作为参数method为形参， func(int, int) int 类型
//	@param num1 参数1
//	@param num2 参数2
//	@return res 返回值
func sumAsParam(method func(int, int) int, num1 int, num2 int) (res int) {
	return method(num1, num2)
}

func expend(n1 int, n2 int) (n3 int, n4 int) {
	n3 = n1 * 2
	n4 = n2 * 2
	return
}

func expendAsParam(method func(int, int) (int, int), n1 int, n2 int) (n3 int, n4 int) {
	return method(n1, n2)
}

// Exchange
//
//	@Description: 交换两个参数
//	@param n1
//	@param n2
//	@return int
//	@return int
func Exchange(n1 int, n2 int) (int, int) {
	return n2, n1
}

// ExchangeAsParam
//
//	@Description:
//	@param method func:testExchangeAsParam
//	@param n1 参数1
//	@param n2 参数2
//	@return n3 返回值2
//	@return n4 返回值1
func ExchangeAsParam(method func(int, int) (int, int), n1 int, n2 int) (n3 int, n4 int) {
	return method(n1, n2)
}

func testExchangeAsParam() {
	method := Exchange
	n3, n4 := expendAsParam(method, 101, 99)
	fmt.Printf("%d %d \n", n3, n4)

}
